package com.rfid.spec;

import java.util.Vector;
import java.util.concurrent.locks.ReentrantLock;

public class ConnectedPICCs {
    private ReentrantLock m_listSync = new ReentrantLock();
    private int m_npCursor = 0;
    private Vector<L0_PICC_HANDLE> m_RegPICCs = new Vector();

    public void Register(L0_PICC_HANDLE h) {
        if (h == null) return;
        this.m_listSync.lock();
        boolean bFind = false;
        for (int i = 0; i < this.m_RegPICCs.size(); i++) {
            L0_PICC_HANDLE p = (L0_PICC_HANDLE) this.m_RegPICCs.get(i);
            if (p == h) {
                bFind = true;
                break;
            }
        }
        if (!bFind) this.m_RegPICCs.add(h);
        this.m_listSync.unlock();
    }

    public L0_PICC_HANDLE Unregister(L0_PICC_HANDLE h) {
        L0_PICC_HANDLE result = null;
        this.m_listSync.lock();
        for (int j = 0; j < this.m_RegPICCs.size(); j++) {
            L0_PICC_HANDLE p = (L0_PICC_HANDLE) this.m_RegPICCs.get(j);
            if (p == h) {
                result = p;
                this.m_RegPICCs.remove(j);
                break;
            }
        }
        this.m_listSync.unlock();
        return result;
    }

    public boolean Find(L0_PICC_HANDLE h) {
        boolean result = false;
        this.m_listSync.lock();
        for (int i = 0; i < this.m_RegPICCs.size(); i++) {
            L0_PICC_HANDLE p = (L0_PICC_HANDLE) this.m_RegPICCs.get(i);
            if (p == h) {
                result = true;
                break;
            }
        }
        this.m_listSync.unlock();
        return result;
    }

    public void RemoveAll() {
        this.m_npCursor = 0;
        this.m_RegPICCs.clear();
    }

    public boolean LC_MoveFirst() {
        if (this.m_RegPICCs.size() > 0) {
            this.m_npCursor = 0;
            return true;
        }
        this.m_npCursor = 0;
        return false;
    }

    public boolean LC_MoveNext() {
        if (this.m_npCursor >= this.m_RegPICCs.size()) return false;
        this.m_npCursor++;
        return true;
    }

    public L0_PICC_HANDLE LC_Get() {
        if (this.m_npCursor >= this.m_RegPICCs.size()) return null;
        return (L0_PICC_HANDLE) this.m_RegPICCs.get(this.m_npCursor);
    }
}
